/**
 * Collaborative Story Development Web Application (CSDApp) Copyright Anton
 * Strack 2014
 *
 * This file is part of Collaborative Story Development Application (CSDApp).
 *
 * CSDApp is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or any later version.
 *
 * CSDApp is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * CSDApp. If not, see <http://www.gnu.org/licenses/>.
 *
 */
package csdwa;

/**
 * This class handles the configuration settings for the CSD web application. It
 * primarily handles settings such as file paths and database connections.
 *
 * @author Anton Strack
 */
public class Configuration {
    /*
     * The configuration values are retrieved by methods to allow for future modifications such as getting values from a file without needing to update the calling code.
     * However, for the version 1 of CSDapp, all the settings will be set in this file itself.
     */

    private String path = null;

    public Configuration() {
    }

    public Configuration(String path) {
        this.path = path;
    }

    /**
     * Get the site name for display on the site.
     *
     * @return the site name;
     */
    public static String getSiteName() {
        return "Uprising Dev";
    }

    /**
     * Get the path variable value.
     *
     * @return the path.
     */
    public String getPath() {
        if (this.path != null) {
            return this.path;
        }
        return "";
    }

    /**
     * The version of the csdwa application.
     *
     * @return the version
     */
    public static String getVersion() {
        return "Version 1.0";
    }

    /**
     * This method returns the JSP directory path for including common items on
     * the page.
     *
     * @return the file/url path for the jsp files, such as header, userColumn,
     * and footer.
     */
    public static String getCommonImportPath() {
        return "/common/";
    }

    /**
     * This method returns the file path for the core bootstrap css file.
     *
     * @return the file/url path for the css file responsible for * controlling
     * the structure and shape of elements.
     */
    public static String getStructureCSS() {
        return "assets/bootstrap/css/bootstrap.css";
    }

    /**
     * This method returns the file path for the theme bootstrap css file.
     *
     * @return the file/url path for the css file responsible for * controlling
     * the theme of the structured elements
     */
    public static String getThemeCSS() {
        return "assets/bootstrap/css/bootstrap-theme.css";
    }

    /**
     * This method returns the file path for the CSDapp specific style and
     * selector rules
     *
     * @return the relative file path for the css file responsible used or
     * referenced by code for the CSDapp.
     */
    public static String getCsdAppCSS() {
        return "assets/CSDapp.css";
    }

    /**
     * This method returns the file path for the core JavaScript file used by
     * the application. Other javascript files will depend on this file.
     *
     * @return the file path/url for the core javascript file.
     */
    public static String getCoreJS() {
        return "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js";
    }

    /**
     * This method returns the file path for the structural JavaScript file used
     * by the application to apply or handle the strctural functionality. This
     * file depends on the CoreJS file and references the StructuredCSS.
     *
     * @return the file path/url for the structural/functional javascript file.
     */
    public static String getStructureJS() {
        return "assets/bootstrap/js/bootstrap.js";
    }

    /**
     * This method returns the file path for the csdapp JavaScript file used by
     * the application to apply or handle some operational functionality. This
     * file depends on the CoreJS file and references the csdapp.css.
     *
     * @return the file path/url for the csdapp javascript file.
     */
    public static String getCsdAppJS() {
        return "assets/js/csdapp.js";
    }

    /**
     * This method returns the database driver name that can be used as a
     * parameter in the Class.forName() method.
     *
     * @return the full database driver name.
     */
    public static String getDbDriver() {
        return "com.mysql.jdbc.Driver";
    }

    /**
     * This method returns the URL to the database that can be used as a
     * parameter in the DriverManager.getConnection() method.
     *
     * @return the full URL to the database.
     */
    public static String getDbURL() {
        //  return "jdbc:mysql://localhost/csdapp_db";
        //  return "mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/dauprising";
        //  return "jdbc:mysql://127.6.12.130:3306/dauprising";

        String APP_NAME = System.getenv("OPENSHIFT_APP_NAME");
        String DB_HOST = System.getenv("OPENSHIFT_MYSQL_DB_HOST");
        String DB_PORT = System.getenv("OPENSHIFT_MYSQL_DB_PORT");
        String DB_CONN = "jdbc:mysql://" + DB_HOST + ":" + DB_PORT + "/" + APP_NAME;
        return DB_CONN;
    }

    /**
     * This method returns the Username that can be used as a parameter in the
     * DriverManager.getConnection() method.
     *
     * @return the username to connect to the database as.
     */
    public static String getDbUser() {
        String DB_USER = System.getenv("OPENSHIFT_MYSQL_DB_USERNAME");
        return DB_USER;

    }

    /**
     * This method returns the Password that can be used as a parameter in the
     * DriverManager.getConnection() method.
     *
     * @return the password to authenticate the the user when connecting to the
     * database.
     */
    public static String getDbPass() {
        String DB_PASSWD = System.getenv("OPENSHIFT_MYSQL_DB_PASSWORD");
        return DB_PASSWD;
    }

    public static int getRecentPlotMaxCount() {
        return 5;
    }

    public static int getRecentLocationMaxCount() {
        return 5;
    }

    public static int getRecentCharacterMaxCount() {
        return 5;
    }

    public static int getRecentDialogMaxCount() {
        return 5;
    }

    public static int getRecentCommentMaxCount() {
        return 12;
    }

    public static int getRecentHistoryMaxCount() {
        return 5;
    }

    public static int getRecentNotificationsMaxCount() {
        return 5;
    }

    public static int getPendingTasksMaxCount() {
        return 12;
    }

    /**
     *
     * @return the session duration in seconds.
     */
    public static int getSessionMaxDuration() {
        return 300 * 60; // 60 = 60 seconds = 1 minute * 300 = 5 hours
    }
}
